package com.donghua.controller;

import com.donghua.entity.Comment;
import com.donghua.service.CommentService;
import com.donghua.util.CommunityConstant;
import com.donghua.util.HostHolder;
import com.donghua.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import static com.donghua.enums.StatusCodeEnum.SUCCESS;

@Controller
@RequestMapping("/comment")
public class CommentController implements CommunityConstant {

    @Autowired
    private CommentService commentService;

    @Autowired
    private HostHolder hostHolder;

    @RequestMapping(path = "/add/{discussPostId}", method = RequestMethod.POST)
    @ResponseBody
    public Result<?> addComment(@PathVariable("discussPostId") int discussPostId, @RequestBody Comment comment) {
        comment.setUserId(hostHolder.getUser().getId());
        comment.setStatus(0);
        comment.setCreateTime(new Date());
        commentService.addComment(comment);

        return Result.ok(SUCCESS.getCode(), SUCCESS.getMsg());
    }

}
